package com.cf.studiomanage.mapper;

import com.cf.studiomanage.entity.Assessment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AssessmentMapper {

    @Insert("INSERT INTO assessment(user_id, type, score, report_url) VALUES(#{userId}, #{type}, #{score}, #{reportUrl})")
    int add(Assessment assessment);

    @Select("SELECT * FROM assessment WHERE user_id = #{userId} ORDER BY created_at DESC")
    List<Assessment> getByUser(Long userId);

    @Select("SELECT * FROM assessment WHERE type = #{type} ORDER BY score DESC LIMIT 10")
    List<Assessment> top10ByType(String type);

    @Delete("DELETE FROM assessment WHERE id = #{id}")
    int deleteById(Long id);
}
